package com.qf.controller;

import com.qf.entity.Emp;
import com.qf.service.EmpService;
import com.qf.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
杨威
2021/9/16
22:26
*/
@WebServlet("/update")
public class UpdateController extends HttpServlet {
    EmpService empService=new EmpServiceImpl();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String salary = request.getParameter("salary");
        String age = request.getParameter("age");
        Emp emp=new Emp(Integer.valueOf(id),name,Double.valueOf(salary),Integer.valueOf(age));
        int i = empService.updateEmp(emp);
        if(i>0){
            response.sendRedirect(request.getContextPath()+"/ShowAll");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
